<template>
	<view class="personal-info">
		<!-- <nav-bar title="我要入驻" color="black" bg="rgba(0,0,0,0)"></nav-bar> -->
		<u-cell-group>

			<view class='ul'>
				<view class='li'>
					<view slot="title" class="u-cell__title required">昵称</view>
					<input class='catname' type="text" v-model="ordersList.nickname" @input="nickInput"
						placeholder="请输入昵称" />
				</view>
			</view>
			<view class='line'></view>
			<!-- <u-cell>
				<view slot="title" class="u-cell__title ">头像</view>
				<image @click="avatarimage" v-if="url_phoneimg != ''"
						src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/d486f37c1f8b7458c01bc2243e0333f252f2b33a.png"
						mode="" style="width: 30rpx; height: 30rpx;position: absolute;right: 16rpx;z-index: 999;">
					</image>
					<image style="width: 84rpx; height: 84rpx;" v-if="url_phoneimg != ''" :src="heading">
					</image>
				<u-upload v-else :fileList="fileList1" name="1" width="80rpx" height="80rpx" @afterRead="afterRead"
						@delete="deletePic" multiple :maxCount="1" />
			</u-cell> -->
			<view class='ul'>
				<view class='li'>
					<view slot="title" class="u-cell__title required">场馆图片</view>
				</view>
			</view>
			<view class='uls'>
				<view class='li'>
					<u-upload :fileList="fileList1" name="1" width="140rpx" height="140rpx" @afterRead="afterRead"
						@delete="deletePic" multiple :maxCount="10" />
				</view>
			</view>
			<view class='line'></view>


			<view class='ul'>
				<view class='li'>
					<view slot="title">场馆描述</view>
					<input class='catname' type="text" v-model="ordersList.base_age" @input="base_ageInput"
						placeholder="请输入场馆描述" />
				</view>
			</view>
			<view class='line'></view>
			<view class='ul'>
				<view class='li'>
					<view slot="title" class="u-cell__title required">姓名</view>
					<input class='catname' type="text" v-model="ordersList.username" @input="nameInput"
						placeholder="请输入名字" />
				</view>
			</view>

			<view class='line'></view>
			<view class='ul'>
				<view class='li'>
					<view slot="title" class="u-cell__title required">手机号</view>
					<input class='catname' type="text" v-model="ordersList.phone" @input="phoneInput"
						placeholder="请输入手机号" />
				</view>
			</view>

		</u-cell-group>
		<view style="width: 100%; height: auto;background: #fff; padding: 20rpx 30rpx;margin-top: 30rpx;
			background-color: white;
			border-radius: 7px;">
			<view style="width: 100%;height: 40rpx;font-size: 26rpx;
								font-weight: 500;
								color: #333333;">需求</view>
			<textarea placeholder=" 请填写需求" class="input-textare" height="200rpx" margin-top='20rpx'
				placeholder-style="font-size: 26rpx" v-model="order_remarks" />
		</view>

		<!-- <view class="btns flex-between" >
			<u-button text="立即申请" shape="circle" color="rgb(249,52,66)" @click="save" size="large"></u-button>
		</view> -->
		<button class="confirm-btn" shape="circle" @click="save()">
			立即申请
		</button>
	</view>
</template>

<script>
	const venues = require("@/api/venues/venues.js");
	export default {
		data() {
			return {
				showInsurancePicker: false,
				userInfo: {
					avatar: '',
					nickname: '文若',
					name: '王越',
					phone: uni.getStorageSync('phone'),
					face: '',
					age: 28,
					height: '172cm',
					gender: '男',
					id: '',
				},
				isEdit: false,
				ordersList: {},
				xiugai: true,
				ordersList: {},
				base_height: '',
				base_sex: '',
				card_num: '',
				base_age: '',
				username: '',
				fileList1: [],
				url_phone: '',
				url_phoneimg: false,
				heading: '',
				columns: {
					insurance: [
						['男', '女']
					]
				},

			}
		},
		onLoad({
			edit = false
		}) {
			this.isEdit = !!edit;
			this.xiugai = true

		},
		methods: {
			confirmPicker({
				value
			}, key) {
				this.ordersList[key] = value.join('');
				// if (this.formData[key] == '是') {
				// 	this.formData.insurance = 1
				// } else{
				// 	this.formData.insurance = 0
				// }
				this[`show${key[0].toUpperCase() + key.slice(1)}Picker`] = false;
			},
			// avatarimage() {
			// 	this.heading = ''
			// 	this.url_phoneimg = false
			// },
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: this.url_phone
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'https://sass-test.doit10019.com/api/upload/uploadOneImage', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							// user: 'test',
							project_id: getApp().globalData.projectId,
							app_id: this.$https.weixinAppId,

						},
						success: (res) => {
							let result = JSON.parse(res.data);
							this.url_phone = result.data.url
							setTimeout(() => {
								resolve(this.url_phone)
							}, 1000)
						}
					});
				})
			},

			// 人脸录入
			faceEntry() {
				if (!this.isEdit) return;
				uni.navigateTo({
					url: '/pages_a/face-entry/face-entry'
				});
			},

			nameInput(e) {
				this.ordersList.username = e.detail.value
			},
			nickInput(e) {
				this.ordersList.nickname = e.detail.value
			},
			base_heightInput(e) {
				this.ordersList.base_height = e.detail.value
			},
			base_sexInput(e) {
				this.ordersList.base_sex = e.detail.value
			},
			card_numInput(e) {
				this.ordersList.card_num = e.detail.value
			},
			base_ageInput(e) {
				this.ordersList.base_age = e.detail.value
			},
			// 保存
			async save() {
				uni.reLaunch({
					url: './index'
				})
				// if (this.heading != '') {
				// 	this.url_phone = this.heading
				// }
				// let param_na = {
				// 	'nickname': this.ordersList.nickname,
				// 	'phone': this.ordersList.phone,
				// 	'base_height': this.ordersList.base_height,
				// 	'base_sex': this.ordersList.insurance,
				// 	'card_num': this.ordersList.card_num,
				// 	'base_age': this.ordersList.base_age,
				// 	'username': this.ordersList.username,
				// 	'headimg': this.url_phone, //头像logo
				// };

				// let params = {
				// 	user_info: JSON.stringify(param_na),
				// 	appid: this.$https.weixinAppId,
				// 	project_id: getApp().globalData.projectId,
				// 	openid: uni.getStorageSync('openid'),
				// };
				// let res = await venues.editUserInfo(params);
				// if (res.code === 1) {
				// 	uni.setStorageSync('username', this.ordersList.username)
				// 	let username = this.ordersList.username
				// 	this.xiugai = true
				// 	uni.reLaunch({
				// 		url: '/pages/my-center/my-center'
				// 	})

				// }
			},
		}
	}
</script>

<style lang="scss" scoped>
	.personal-info {
		background-color: #f7f7f7;
		min-height: 100vh;
		padding-bottom: calc(190rpx + env(safe-area-inset-bottom));

		.confirm-btn {
			width: 90%;
			height: 80rpx;
			line-height: 80rpx;
			background-color: rgb(255, 101, 85);
			border-radius: 40rpx;
			text-align: center;
			color: #fff;
			float: inherit;
			margin: 100rpx 38rpx 25rpx 38rpx;
		
		}
		/deep/.u-cell-group {
			background-color: #fff;
			flex-grow: 0;

			.u-cell-group__wrapper>.u-line {
				display: none;
			}

			.u-cell__body {
				padding: 0 18rpx 0 32rpx;
				height: 110rpx;
			}

			.u-cell__title {
				color: #333;
				font-size: 32rpx !important;
				font-weight: 500;

				&.required {
					&::before {
						content: '*';
						color: #fb2222;
					}
				}
			}

			.u-cell__value {
				color: #999;
			}
		}

		.btns {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			padding: 30rpx;
			padding-bottom: calc(30rpx + env(safe-area-inset-bottom));

			/deep/.u-button {
				&+.u-button {
					margin-left: 20rpx;
				}
			}
		}

		.wrap {
			overflow: hidden;
		}

		.ul {
			width: 92%;
			height: 110rpx;
			margin: auto;
		}

		.uls {
			width: 92%;
			height: 160rpx;
			margin: auto;
			
			.li {
				width: 100%;
				height: 160rpx;
				line-height: 160rpx;
				display: flex;
				justify-content: space-between;
			}
		}

		.li {
			width: 100%;
			height: 110rpx;
			line-height: 110rpx;
			display: flex;
			justify-content: space-between;
		}


		.li .left {
			font-size: 32rpx;
			color: #333;
			text-align: left;
		}


		.catname {
			color: #999;
			margin-left: 10rpx;
			margin-top: 40rpx;
			font-size: 26rpx;
		}

		.catnames {
			color: #999 !important;
			font-size: 26rpx;
		}

		input {
			text-align: right;
		}

		.line {
			width: 100%;
			height: 1rpx;
			background-color: #e6e6e6
		}



	}
</style>
